<?php

namespace app\zz_article\controller;

use app\common\controller\Api;
use app\zz_article\model\ArticleM;
use think\Validate;

class ArticleList extends Api
{
    protected $noNeedLogin = '*';

    public function index()
    {
        $validate = new Validate();
        if (!$validate->check(input(), [
            'banner_is' => 'min:1',
            'type_id'   => 'integer',
            'page'      => 'integer',
        ])) {
            $this->error($validate->getError());
        }
        $banner_is = input('banner_is');
        $type_id   = input('type_id');
        $page      = input('page');
        $query     = ArticleM::hasWhere('type', [
            'ArticleTypeM.status' => 'normal',
        ])->where('ArticleM.status', 'normal');
        if ($banner_is) {
            $query->where('ArticleM.banner_is', $banner_is);
        }
        if ($type_id) {
            $query->where('ArticleM.type_id', $type_id);
        }
        if ($page) {
            $list = $query->paginate(10, ['page' => $page]);
        } else {
            $list = $query->select();
        }
        $this->success('', $list);
    }
}
